<template>
  <div>
    <el-form>
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item>
            <el-input></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item>
            <el-button type="primary">
              查询
            </el-button>
            <el-button type="primary">
              清空
            </el-button>
            <el-button type="primary" @click="add()">
              增加
            </el-button>
            <el-button type="danger" @click="deleteAll()">
              批量删除
            </el-button>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>

    <!--表格内容-->
    <el-table ref="carouselChartForm" :data="tableData" style="width: 100%; margin-bottom: 5px" border stripe
      highlight-current-row :default-sort="{ prop: 'date', order: 'descending' }"
      :header-cell-style="{ textAlign: 'center' }" :cell-style="{ textAlign: 'center' }">
      <el-table-column fixed type="selection">
      </el-table-column>
      <el-table-column property="name" label="机构名称">
      </el-table-column>
      <el-table-column property="type" label="类型">
      </el-table-column>
      <el-table-column property="introduction" label="简介">
      </el-table-column>
      <!-- <el-table-column property="province" label="省份">
                  </el-table-column>
                  <el-table-column property="city" label="所在城市">
                  </el-table-column> -->
      <el-table-column property="address" label="地址">
      </el-table-column>
      <el-table-column property="phone" label="联系电话">
      </el-table-column>
      <el-table-column property="remark" label="备注">
      </el-table-column>

      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-edit-outline" type="primary" title="编辑" size="small"
            @click="rowEdit(scope.row)"></el-button>
          <el-button circle icon="el-icon-delete" type="danger" title="删除" size="small" @click="rowDel(scope.row.id)">
          </el-button>

        </template>
      </el-table-column>


    </el-table>
    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40, 100]" :page-size="10" :total="100"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <Edit v-if="isShowEditDialog" :isShowEditDialog="isShowEditDialog" :record="formFileds" @dialogClose="dialogClose"></Edit>
    <Add v-if="isShowAddDialog" :isShowAddDialog="isShowAddDialog" @dialogClose="dialogClose" @getList="getList">
    </Add>
  </div>
</template>
                  
<script>
import Edit from "./cooperationEdit";
import Add from "./cooperationAdd";
import { getAll, delCooperation } from '@/api/systemAdministrator/cooperationManage';
export default {
  name: "CooperationManage",
  components: {
    Edit,
    Add,
  },
  data () {
    return {
      formFileds: {},
      tableData: [],
      isShowEditDialog: false,
      isShowAddDialog: false,

    };
  },
  methods: {
    dialogClose () {
      this.isShowEditDialog = false;
      this.isShowAddDialog = false;
    },
    submitData () {
      console.log('提交');
    },
    add () {
      this.isShowAddDialog = true;
    },
    rowEdit (row) {
      // //当前选中行
      this.formFileds = row;
      this.isShowEditDialog = true;
    },
    rowDel (id) {
      // 让当前删除按钮失焦
      // event.target.blur();

      this.$confirm("确定要删除当前行吗？", "删除", {
        comfirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        delCooperation(id).then((res) => {
          this.$message.success("删除成功");
          this.getList();
        })
      });
    },
    deleteAll () {
      this.$confirm("确定要删除这些行吗？", "删除", {
        comfirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        this.$message.success("删除成功");
        return false;
      });
    },
    // 选中当前行-当前行的复选框被勾选
    setCurRowChecked (row) {
      this.$refs.carouselChartForm.clearSelection();
      this.$refs.carouselChartForm.toggleRowSelection(row);
    },
    getList () {
      getAll().then((res) => {
        console.log(res.data);
        this.tableData = res.data;
      })
    },
  },
  mounted () {
    this.getList();
  }
};
</script>
                  
<style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}
</style>
